<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>数据统计</title>
    <script src="./js/echarts.min.js"></script>
    <script src="./js/jquery.js"></script>
</head>
<body>
<div id="main1" style="width: 600px;height:400px;float: left;"></div>
<script type="text/javascript">
    // 基于准备好的dom，初始化echarts实例
    var myChart1 = echarts.init(document.getElementById('main1'));
    $.ajax({
        type: "GET",
        url: "/count/songList",
        dataType: "json",
        success: (result, xhr, status) => {
            if (result.status == 200) {
                // 指定图表的配置项和数据
                var option1 = {
                    title: {
                        text: '歌单播放量'
                    },
                    tooltip: {},
                    legend: {
                        data: ['播放量']
                    },
                    xAxis: {
                        data: [result.data[0].objName, result.data[1].objName, result.data[2].objName, result.data[3].objName, result.data[4].objName]
                    },
                    yAxis: {},
                    series: [
                        {
                            name: '播放量',
                            type: 'bar',
                            data: [result.data[0].count, result.data[1].count, result.data[2].count, result.data[3].count, result.data[4].count]
                        }
                    ]
                };
                // 使用刚指定的配置项和数据显示图表。
                myChart1.setOption(option1);
            }
        }
    })
</script>

<div id="main2" style="width: 600px;height:400px;float: left;"></div>
<script type="text/javascript">
    // 基于准备好的dom，初始化echarts实例
    var myChart2 = echarts.init(document.getElementById('main2'));
    $.ajax({
        type: "GET",
        url: "/count/song",
        dataType: "json",
        success: (result, xhr, status) => {
            if (result.status == 200) {
                // 指定图表的配置项和数据
                var option2 = {
                    title: {
                        text: '歌曲播放量'
                    },
                    tooltip: {},
                    legend: {
                        data: ['播放量']
                    },
                    xAxis: {
                        type: 'category',
                        data: [result.data[0].objName, result.data[1].objName, result.data[2].objName, result.data[3].objName, result.data[4].objName]
                    },
                    yAxis: {
                        type: 'value'
                    },
                    series: [
                        {
                            name: '播放量',
                            type: 'bar',
                            data: [result.data[0].count, result.data[1].count, result.data[2].count, result.data[3].count, result.data[4].count],
                            showBackground: true,
                            backgroundStyle: {
                                color: 'rgba(120,120,120,0.2)'
                            }
                        }
                    ]
                };
                // 使用刚指定的配置项和数据显示图表。
                myChart2.setOption(option2);
            }
        }
    })
</script>
<div id="main3" style="width: 600px;height:400px;float: left;"></div>
<script type="text/javascript">
    // 基于准备好的dom，初始化echarts实例
    var myChart3 = echarts.init(document.getElementById('main3'));
    $.ajax({
        type: "GET",
        url: "/count/mv",
        dataType: "json",
        success: (result, xhr, status) => {
            if (result.status == 200) {
                // 指定图表的配置项和数据
                var option3 = {
                    title: {
                        text: 'MV播放量'
                    },
                    tooltip: {},
                    legend: {
                        data: ['播放量']
                    },
                    xAxis: {
                        type: 'category',
                        data: [result.data[0].objName, result.data[1].objName, result.data[2].objName, result.data[3].objName, result.data[4].objName]
                    },
                    yAxis: {
                        type: 'value'
                    },
                    series: [
                        {
                            name: '播放量',
                            type: 'bar',
                            data: [result.data[0].count, result.data[1].count, result.data[2].count, result.data[3].count, result.data[4].count],
                            showBackground: true,
                            backgroundStyle: {
                                color: 'rgba(120,120,120,0.2)'
                            }
                        }
                    ]
                };
                // 使用刚指定的配置项和数据显示图表。
                myChart3.setOption(option3);
            }
        }
    })
</script>

<div id="main4" style="width: 600px;height:400px;float: left;"></div>
<script type="text/javascript">
    // 基于准备好的dom，初始化echarts实例
    var myChart4 = echarts.init(document.getElementById('main4'));
    $.ajax({
        type: "GET",
        url: "/count/album",
        dataType: "json",
        success: (result, xhr, status) => {
            if (result.status == 200) {
                // 指定图表的配置项和数据
                var option4 = {
                    title: {
                        text: '专辑销量',
                        left: 'center'
                    },
                    tooltip: {trigger: 'item'},
                    legend: {
                        data: ['销量'],
                        orient: 'vertical',
                        left: 'left'
                    },
                    series: [
                        {
                            name: '销量',
                            type: 'pie',
                            radius: '50%',
                            data: [
                                { value: result.data[0].count, name: result.data[0].objName },
                                { value: result.data[1].count, name: result.data[1].objName },
                                { value: result.data[2].count, name: result.data[2].objName },
                                { value: result.data[3].count, name: result.data[3].objName },
                                { value: result.data[4].count, name: result.data[4].objName }
                            ],
                            emphasis: {
                                itemStyle: {
                                    shadowBlur: 10,
                                    shadowOffsetX: 0,
                                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                                }
                            }
                        }
                    ]
                };
                // 使用刚指定的配置项和数据显示图表。
                myChart4.setOption(option4);
            }
        }
    })
</script>
</body>
</html>